import Types from '../actionTypes';
import {
  getSelfBeforeLsit,
  getInvoiceInfo,
  getOrderDetais,
  receivingList,
  getPaymentInfo
} from '../../api';

/**
 *
 * @param page
 * @returns {Function}
 * @constructor
 */
const GET_SELF_BEFORE_LIST = (page) => {

  return new Promise((resolve, reject) => {
    getSelfBeforeLsit(page).then(res => {
      console.log(res);
      resolve({
        type: Types.GET_SELF_BEFORE_LIST,
        data: res
      });
    }).catch(err => {
      console.log(err);
    });
  });
};

/**
 *
 * @param invoice_id
 * @returns {Promise<unknown>}
 * @constructor
 */
const GET_INVOICE_INFO = (invoice_address_id, user_id, invoice_type) => {
  return new Promise((resolve, rej) => {
    getInvoiceInfo(invoice_address_id, user_id, invoice_type).then(data => {
      resolve({
        type: Types.GET_INVOICE_INFO,
        data: data.data
      });
    }).catch(err => {
      console.log(err);
    });
  });
};

const GET_ORDER_DETAILS = order_no => {
  return new Promise((resolve, rej) => {
    getOrderDetais(order_no).then(data => {
      resolve({
        type: Types.GET_ORDER_DETAILS,
        data: data.order[0].goods
      });
    }).catch(err => {
      console.log(err);
    });
  });
};

// getPaymentInfo
const GET_PAYMENT_INFO = id => {
  return new Promise((resolve, rej) => {
    getPaymentInfo(id).then(data => {
      resolve({
        type: Types.GET_PAYMENT_INFO,
        data: data
      });
    }).catch(err => {
      console.log(err);
    });
  });
};


export default {
  GET_SELF_BEFORE_LIST,
  GET_INVOICE_INFO,
  GET_ORDER_DETAILS,
  GET_PAYMENT_INFO
};
